/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ipartek.formacion.gestformwww.controlador;

import com.ipartek.formacion.gestformwww.modelo.ModeloMaterial;
import com.ipartek.formacion.gestformwww.modelo.beans.Convocatoria;
import com.ipartek.formacion.gestformwww.modelo.beans.FiltroMaterial;
import com.ipartek.formacion.gestformwww.modelo.beans.Material;
import com.ipartek.formacion.gestformwww.modelo.beans.excepciones.GestorFormacionExcepcion;
import com.ipartek.formacion.gestformwww.modelo.clases.SQLServerConvocatoriaDAO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Curso
 */
public class PruebaMain extends HttpServlet {
ResourceBundle bundle;

    private AccionFactory factory;
    private static boolean prueba=false;

    public static void setPrueba(boolean prueba) {
        PruebaMain.prueba = prueba;
    }

    

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        ArrayList<Convocatoria> convocatorias = null;
        SQLServerConvocatoriaDAO scd = new SQLServerConvocatoriaDAO();
        String url = "mostrarCatalogo.jsp";

        request.setAttribute("usuario", "admin");
        request.setAttribute("pass", "admin");
        request.getSession().setAttribute("usuario", request.getAttribute("usuario"));
        request.getSession().setAttribute("pass", request.getAttribute("pass"));
        FiltroMaterial filtro = new FiltroMaterial(bundle);

        ModeloMaterial modelo=new ModeloMaterial();
        try {
            ArrayList<Material> materiales=modelo.listarMateriales(filtro);
            for(Material m:materiales)
            {
                System.out.println(m.getIsbn()+"\n");
            }
        } catch (GestorFormacionExcepcion ex) {
            Logger.getLogger(PruebaMain.class.getName()).log(Level.SEVERE, null, ex);
        }

        
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        SQLServerConvocatoriaDAO scd = new SQLServerConvocatoriaDAO();


    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        
        factory = new AccionFactory();
        ServletContext sc = config.getServletContext();
        ModeloMaterial modelo= new ModeloMaterial();
        sc.setAttribute("ModeloConvocatoria", modelo);
        String recurso = config.getInitParameter("acciones-mapeo");
        bundle = ResourceBundle.getBundle(recurso);
        sc.setAttribute("acciones-mapeo", bundle);
        recurso = config.getInitParameter("errores-mapeo");
        bundle = ResourceBundle.getBundle(recurso);
        sc.setAttribute("errores-mapeo", bundle);
        recurso = config.getInitParameter("mensajes-mapeo");
        bundle = ResourceBundle.getBundle(recurso);
        sc.setAttribute("mensajes-mapeo", bundle);
        recurso = config.getInitParameter("mailPlantillas-mapeo");
        bundle = ResourceBundle.getBundle(recurso);
        sc.setAttribute("mailPlantillas-mapeo", bundle);
        sc.setAttribute("ModeloMaterial",modelo);


    }
}
